﻿using B.S.Base.Write.API.Application.Command;
using MediatR;
using WEBAPI.Damoin;
using WEBAPI.ErroeCode;
using WEBAPI.Indaseture.Infasetures;

namespace B.S.Base.Write.API.Application.CommandHandLer
{
    public class DeleteApproveCommandHandLer : IRequestHandler<DeleteApproveCommand, APIResult<int>>
    {
        private readonly IBaseRepostiy<ApproveModel> menu;

        public DeleteApproveCommandHandLer(IBaseRepostiy<ApproveModel> menu)
        {
            this.menu = menu;
        }
        public Task<APIResult<int>> Handle(DeleteApproveCommand request, CancellationToken cancellationToken)
        {
            APIResult<int> result = new APIResult<int>();

            var list = menu.GetAll().FirstOrDefault(x => x.Id == request.Id);
            if (list != null)
            {
                result.Code = ResultCode.Ok;
                result.Message = "删除成功";
                list.IsDel = true;
                menu.Update(list);
            }
            return Task.FromResult(result);
        }
        
    }
}
